package models.report;

import java.util.*;

import play.Logger;
import play.db.ebean.*;
import play.db.ebean.Model.Finder;
import play.data.validation.Constraints.*;
import play.data.format.*;
import play.mvc.Http.Context;
import play.mvc.Http.Request;
import service.Paging;

import javax.persistence.*;

import models.monitor.ScheduleETL;

import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.ExpressionList;
import com.avaje.ebean.Page;
import com.avaje.ebean.PagingList;
import com.avaje.ebean.Query;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class Product extends Model{
	@Id
	@JsonIgnore
	public Integer productKey;
	
	public Integer productId;
	
	public String productName;
	
	@JsonIgnore
	public String type;
	
	public static Finder<Long,Product> find = new Finder(
		Long.class, Product.class
	);
	
	public static Paging search(){		
		Request request = Context.current().request();
		
		int pageSize = Integer.parseInt(request.getQueryString("pageSize"));
    	int page = Integer.parseInt(request.getQueryString("page"));
    	
    	EbeanServer desperado = Ebean.getServer("desperado");
    	
    	Query<Product> query = desperado.find(Product.class);
    	
    	ExpressionList<Product> expression = query.where();
    	
    	PagingList<Product> pagingList = expression.findPagingList(pageSize);
    	
    	Page<Product> page0 = pagingList.getPage(page - 1);
        List<Product> list = page0.getList();
        
        Paging paging = new Paging(pagingList.getTotalRowCount(), list);
        
        return paging;
	}
}
